﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tigera.Network;

namespace Plugin.TradeSharp
{
    public partial class UCLogSetting : UserControl
    {
        public UCLogSetting()
        {
            FormLogin.Login();
            InitializeComponent();           
            this.DataBindings.Add("Enabled", AuthUserService.Instance, "Logined", false, DataSourceUpdateMode.OnPropertyChanged);

            
            //RemoveListen();

        }

        private void btn_MqMsgGet_Click(object sender, EventArgs e)
        {
            AppMgr.Instance.Mqclient.AddPublicListenMailBox(BusinessType.BulletinTopic, BusinessType.TBulletinTopic.ServerErrorTopic);

            AppMgr.Instance.Mqclient.OnNotificationResponse -= Mqclient_OnNotificationResponse;
            AppMgr.Instance.Mqclient.OnNotificationResponse += new EventHandler<Tigera.LibCommon.TiEventArgs<Tigera.T_Definition.T_NotificationResponse>>(Mqclient_OnNotificationResponse);
        }

        void Mqclient_OnNotificationResponse(object sender, Tigera.LibCommon.TiEventArgs<Tigera.T_Definition.T_NotificationResponse> e)
        {
            var msg = e.Data.MsgSendTime.ToString()  + "--"+ e.Data.MsgSubject + ":" + e.Data.MsgContent + System.Environment.NewLine;
            this.richTextBox1.AppendText(msg);
        }


        //TODO ,ADD CLOSE TO REMOVE LISTEN FUNCITON
        void RemoveListen()
        {
            if (AppMgr.Instance.Mqclient.IsAlive)
            {
                AppMgr.Instance.Mqclient.RemovePublicListenMailBox(BusinessType.BulletinTopic, BusinessType.TBulletinTopic.ServerErrorTopic);
            }
            
        }
    }
}
